package com.briup.pts.config.auth;

import com.briup.pts.domain.bean.Account;

/**
 * 认证用户上下文数据
 */
public class SecurityContext {
    private static final ThreadLocal<Account> ACCOUNT_MAP = new ThreadLocal<>();

    public static void setCurrentUser(Account account){
        ACCOUNT_MAP.set(account);
    }

    public static Account currentUser(){
        return ACCOUNT_MAP.get();
    }

    public static String currentUserId(){
        return currentUser().getAccountId();
    }

    public static String username(){
        return currentUser().getUsername();
    }

    public static void clear(){
        ACCOUNT_MAP.remove();
    }
}
